/*
 *奖金列表
 */
require(['jquery','../modules/pageSize','../modules/popup', 'jqScroller'],function($,pageSetSize,popup){
    //设置html根目录字体大小
    setRootFontSize(pageSetSize);
    var _isPopFirst = true;
    $("#reward-use-help").on("click", function(){
        _global.promote.popup(".ask-help-dialog", !_isPopFirst);
        if(_isPopFirst){
            _isPopFirst = false;
        }
    });
    if(_isInHistory){
        $("#ycRewardFilter").on("click", function(){
            $(this).addClass('on');
            $("#ycRewardDrops").css("display", "block");
        });
        $("#ycRewardDrops a").on("click", function(){
            if(!$(this).hasClass("on")){
                _rtype = $(this).attr("data-type");
                curPagePos = 1;
                $("#ajax-reward-list").empty();
                $("#ycRewardFilter").removeClass('on');
                $("#ycRewardDrops").css("display", "none");
                $(this).addClass("on").siblings().removeClass('on');
                jqScroller.render(1);
            }           
        });
    }    
    var curPagePos = 1;
    /*请求奖金列表*/
    jqScroller.render = function(cpage){
        popup.loadPopup("正在加载中...");
        $.ajax({
            type: "POST",
            url: "/Home/Member/bonusLogAjax"+getFixedExtraUrl(),
            data: { "page" : cpage, "type" : _rtype},
            dataType: "json",
            success: function (rs) {
                popup.removeLoad();
                if(rs && rs.data != null)  {
                    renderRewardList(rs.data);
                    curPagePos++;
                    jqScroller.curPage++;
                    jqScroller.unblock();
                }else{
                    jqScroller.done();
                    if(curPagePos == 1){
                        $("#ajax-reward-list").html("<div class='no-data-txt'>没有数据！</div>");    
                    }else{                        
                        popup.alertPopup("没有更多数据！");
                    }                    
                }              
            },
            error: function () {
                popup.removeLoad();
                popup.alertPopup('服务器异常，请稍后重试！');
                jqScroller.unblock();
            }
        });
    };
    jqScroller.run();
    jqScroller.render(1);
    /*渲染奖金列表*/
    function renderRewardList(list){
        var output = "";
        var c;
        for(var k in list){
            c = list[k];
            output += '<div class="one-info">';
            output += '<div class="col-l">';
            output += '<span class="uname">'+c["username"]+'</span>';
            output += '<span class="gname">'+c["goodsname"]+'</span>';
            output += '</div>';
            output += '<div class="col-r">';
            output += '<span class="time">'+c["buytime"]+'</span>';
            if(parseFloat(c["jlnum"]) >= 0){
                output += '<span class="rnum g">+'+c["jlnum"]+'</span>';
            }else {
                output += '<span class="rnum t">' + c["jlnum"] + '</span>';
            }
            output += '</div>';
            output += '</div>';
        }
        if(curPagePos % 10 == 0 || curPagePos == 1){
            $("#ajax-reward-list").html(output); 
        }else{
            $("#ajax-reward-list").append(output);
        }
    }
});